﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace FinalWeb
{
    public partial class UserFirst : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //this.lblInfo.Text = "当前用户是：" + Session["UseName"].ToString();

            this.lblUserIN.Text = "您好！" + Session["UserName"].ToString();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112102;uid=2014112102;pwd=19960523";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string strSql = "UPDATE Members SET MemId=N'" + this.txtNo.Text + "',Name=N'" + this.txtName.Text + "',Gender=N'" + this.DropDownList1.Text + "',Birth=N'" + this.txtBirth.Text + "',Job=N'" + this.txtJob.Text + "',Salary=N'" + this.txtSal.Text + "',Tel=N'" + this.txtTel.Text + "',Address=N'" + this.txtAddr.Text + "' WHERE(MemId=N'" + this.txtNo.Text + "')";
               
                SqlCommand cmd = new SqlCommand(strSql, cn);
                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    Response.Write(@"<script>alert('保存失败！');</script>");
                }
                else
                {
                    Response.Write(@"<script>alert('保存成功！');</script>");
                }
            }
            catch (Exception ex)
            {
                this.lblMessage.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {

        }

        protected void btnRef_Click(object sender, EventArgs e)
        {
            this.txtName.Text = "";
            this.txtNo.Text = "";
            this.txtBirth.Text = "";
            this.txtAddr.Text = "";
            this.txtJob.Text = "";
            this.txtSal.Text = "";
            this.txtTel.Text = "";
            this.DropDownList1.Text = "";

        }

        protected void btnOpen_Click(object sender, EventArgs e)
        {
            string strSql = "SELECT   MemId, Name, Gender, Birth, Job, Salary, Tel, Address FROM  Members WHERE   (MemId = @MemId)";
            SqlParameter[] pms=new SqlParameter[1];
            pms[0] = new SqlParameter("@MemId", Session["UserName"]);
            SqlDataReader dr = WebApp.SqlHelper.ExecuteReader(strSql, pms);
            if (dr.Read())
            {
                this.txtNo.Text = dr["MemId"].ToString();
                this.txtName.Text = dr["Name"].ToString();
                this.DropDownList1.Text = dr["Gender"].ToString();
                this.txtBirth.Text = dr["Birth"].ToString();
                this.txtJob.Text = dr["Job"].ToString();
                this.txtTel.Text = dr["Tel"].ToString();
                this.txtSal.Text = dr["Salary"].ToString();
                this.txtAddr.Text = dr["Address"].ToString();
            } dr.Close();
                
        }

        protected void btnIndex_Click(object sender, EventArgs e)
        {
            //Response.Write(@"<script>alert('注销成功，欢迎下次登陆！');</script>");
            Response.Write(@"<script language=javascript>alert('注销成功，欢迎下次登陆！');window.window.location.href='UserLogin.aspx';</script>"); 
        }

        
    }
}